import express from 'express';
import upload from '../middleware/upload.js';
import {
  getAllProducts,
  getProductById,
  createProduct,
  updateProduct,
  deleteProduct,
  deleteProductImage
} from '../controllers/productController.js';

const router = express.Router();

router.get('/', getAllProducts);
router.get('/:id', getProductById);

router.post('/', 
  upload.fields([
    { name: 'main_image', maxCount: 1 },
    { name: 'images', maxCount: 10 }
  ]), 
  createProduct
);

router.put('/:id',
  upload.fields([
    { name: 'main_image', maxCount: 1 },
    { name: 'images', maxCount: 10 }
  ]),
  updateProduct
);

router.delete('/:id', deleteProduct);
router.post('/:id/delete-image', deleteProductImage);

export default router;

